﻿using System;
using System.Net;
using System.Web.UI.WebControls;

public partial class Katalog_Podlogi : BasePage
{
    private static readonly string _localSources = "/Site/App_Code/Sources/";
    private HttpWebRequest _request;
    protected void Page_Load(object sender, EventArgs e)
    {
        string path = Server.MapPath(_localSources + "LastA.xml");
        RegisterAsyncTask(
            AsyncDownloader.GetTask(
                path, 
                "http://www.nbp.pl/kursy/xml/LastA.xml",
                new EventHandler(OnTaskFinish)
            )
        );
    }


    private void OnTaskFinish(object sender, EventArgs e)
    {
        LoadRatesFromDatabase();
    }

    private void LoadRatesFromDatabase()
    {
        Trace.Warn(AsyncDownloader.Log.ToString()+"\nLoad Rates From Database");
        DataClassesDataContext context = new DataClassesDataContext();
        ExchangeRates.DataSource = context.GetTable<KursyA>();
        ExchangeRates.DataBind();
    }
    protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        ExchangeRates.PageIndex = e.NewPageIndex;
        DataClassesDataContext context = new DataClassesDataContext();
        ExchangeRates.DataSource = context.GetTable<KursyA>();
        ExchangeRates.DataBind();
    }
}